package it.polimi.travelDream.ejb.servlet;

import it.polimi.travelDream.ejb.interfaces.HotelMgrRemote;
import it.polimi.travelDream.ejb.interfaces.PackageMgrRemote;
import it.polimi.travelDream.entities.Package;

import java.io.IOException;
import java.util.Map;
import java.lang.Object;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TravelServlet
 */
@WebServlet("/AddPackage")
public class AddPackage extends HttpServlet {
	private static final long serialVersionUID = 1L;


	@EJB
	PackageMgrRemote pmgr;
	
	
	public AddPackage() {
		super();
	}


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Map<String, String[]> mappa = request.getParameterMap();
		Package pack = new Package();	
		pack = pmgr.addPack(mappa.get("name")[0]);
		int a=pack.getID();
		request.setAttribute("idPackage", a);
		request.setAttribute("message","Package "+ mappa.get("name")[0] +" succesfully created. Now insert travels into "+ mappa.get("name")[0]);
		request.getRequestDispatcher("/PCreatePackage2.jsp").forward(request, response); 
		//response.getOutputStream().println("<h1>TravelDream</h1><h2>" + mappa.get("name")[0]+ " succesfully registered!</h2>" + "| <a href=\"Index.jsp\"> Login </a> | Registration |");
	}

}
